﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ThanhTu.GNCMedia.KQXS.DataAccess.DAL;
using System.Data;
using ThanhTu.GNCMedia.KQXS.DataAccess.DO;

namespace WebUI.Admin
{
    public partial class ModifiedHomePage1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownList1.Items.Add("top");
                DropDownList1.Items.Add("left");
                DropDownList1.Items.Add("right");
                DropDownList1.Items.Add("buttom");
                fuHomePage.Visible = true;
                txt_buttom.Visible = false;
            }
        }
        private bool checkData(string settingName, string settingType, string position, string settingValue)
        {
            bool result = false;

            if (!settingName.Trim().Equals(""))
            {
                result = true;
            }
            else
            {
                result = false;
            }
            if (!settingType.Trim().Equals(""))
            {
                result = true;
            }
            else
            {
                result = false;
            }
            if (!position.Trim().Equals(""))
            {
                result = true;
            }
            else
            {
                result = false;
            }

            if (!settingValue.Trim().Equals(""))
            {
                result = true;
            }
            else
            {
                result = false;
            }
            return result;
        }
        protected void btn_addNewData_Click1(object sender, EventArgs e)
        {
            StyleLotteryDAL styleHomePageDAL = new StyleLotteryDAL();
            StyleLotteryDO styleHomePageDO = new StyleLotteryDO();

            if (DropDownList1.SelectedItem.Text.Equals("buttom"))
            {
                styleHomePageDO.Settingname = txt_settingName.Text;
                styleHomePageDO.Settingtype = txt_settingtype.Text;
                styleHomePageDO.Position = DropDownList1.SelectedValue;
                styleHomePageDO.Settingvalue = txt_buttom.Text;
                int checkUpdate = styleHomePageDAL.update(styleHomePageDO);
                if (checkUpdate > 0)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowStatus", "javascript:alert('Chỉnh sửa giao diện thành công ');", true);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowStatus", "javascript:alert('Chỉnh sửa giao diện thất bại');", true);
                }
            }
            else
            {
                styleHomePageDO.Settingname = txt_settingName.Text;
                styleHomePageDO.Settingtype = txt_settingtype.Text;
                styleHomePageDO.Position = DropDownList1.SelectedValue;
                fuHomePage.SaveAs(Server.MapPath("images") + "//" + fuHomePage.FileName);
                styleHomePageDO.Settingvalue = "../Admin/images/" + fuHomePage.FileName.ToString();
                int checkUpdate = styleHomePageDAL.update(styleHomePageDO);
                if (checkUpdate > 0)
                {

                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowStatus", "javascript:alert('Chỉnh sửa giao diện thành công ');", true);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowStatus", "javascript:alert('Chỉnh sửa giao diện thất bại');", true);
                }
            }
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DropDownList1.SelectedItem.Text.Equals("buttom"))
            {
                fuHomePage.Visible = false;
                txt_buttom.Visible = true;
            }
            else
            {
                fuHomePage.Visible = true;
                txt_buttom.Visible = false;
            }
        }

    }
}